@startuml crd-relationships

skinparam nodesep 80
skinparam ranksep 80
skinparam object {
    backgroundColor<< deckhouse.io/v1 >> #ade8ff
    backgroundColor<< infrastructure.cluster.x-k8s.io/v1alpha1 >> #D9EAD3
    backgroundColor<< deckhouse.io/v1alpha1 >> #faf6bb
}

' deckhouse.io/v1
object NodeGroup << deckhouse.io/v1 >> {
    <font color="Green">spec.staticInstances.labelSelector: StaticInstance.metadata.labels</font>
    spec.staticInstances.count
}

' cluster.x-k8s.io/v1beta1
object Cluster << cluster.x-k8s.io/v1beta1 >> {
    <font color="Green">spec.infrastructureRef: StaticCluster</font>
    <font color="Red">spec.controlPlaneRef: StaticControlPlane</font>
}

object MachineDeployment << cluster.x-k8s.io/v1beta1 >> {
    spec.clusterName
    <font color="Green">spec.template.spec.infrastructureRef: StaticMachineTemplate</font>
    <font color="Red">spec.template.spec.bootstrap.dataSecretName: Secret</font>
    spec.replicas: NodeGroup.spec.staticInstances.count
}
object MachineSet << cluster.x-k8s.io/v1beta1 >> {
    <font color="Green">spec.template.spec.infrastructureRef: StaticMachineTemplate</font>
    <font color="Red">spec.template.spec.bootstrap.dataSecretName: Secret</font>
}
object Machine << cluster.x-k8s.io/v1beta1 >> {
    <font color="Green">spec.infrastructureRef: StaticMachine</font>
    <font color="Red">spec.bootstrap.dataSecretName: Secret</font>
}

' infrastructure.cluster.x-k8s.io/v1alpha1
object StaticControlPlane << infrastructure.cluster.x-k8s.io/v1alpha1 >> {
    status.ready: true
    <font color="Green">status.externalManagedControlPlane: true</font>
}

' core/v1
object Secret << core/v1 >> {
   metadata.name: manual-bootstrap-for-{{ NodeGroup.metadata.name }}
}

' Infrastructure provider CRD
object StaticCluster << infrastructure.cluster.x-k8s.io/v1alpha1 >> {
  status.ready: true
}

object StaticMachineTemplate << infrastructure.cluster.x-k8s.io/v1alpha1 >> {
  spec.labelSelector: StaticInstance.metadata.labels
}

object StaticMachine << infrastructure.cluster.x-k8s.io/v1alpha1 >> {
  spec.labelSelector: StaticInstance.metadata.labels
  spec.providerID: Node.spec.providerID
}

object StaticInstance << deckhouse.io/v1alpha1 >> {
  spec.address
  spec.credentialsRef: SSHCredentials

  status.machineRef: StaticMachine
  status.nodeRef: Node
}

object SSHCredentials << deckhouse.io/v1alpha1 >> {
}

object Node << core/v1 >> {
  spec.providerID
}

object Instance << deckhouse.io/v1 >> {
  status.machineRef: Machine
  status.nodeRef: Node
  status.currentStatus.phase: Machine.status.phase
}

' The straight lines (-->) represent "management". For example, "MachineSet
' manages Machines". The dotted line (..>)represents "reference". For example,
' "Machine `spec.infrastructureRef` field references StaticMachine".
'
' The direction of the arrows indicates the direction of "management" or
' "reference". For example, "the relationship between MachineSet and Machine is
' management from MachineSet to Machine", so the arrow points from MachineSet
' to Machine.

NodeGroup "1" --> "1" MachineDeployment
NodeGroup "1" --> "1" StaticMachineTemplate

MachineDeployment "1..*" .left.> "1" Cluster
MachineDeployment "1" ..> "1" StaticMachineTemplate
MachineDeployment "1" --> "1" MachineSet
MachineDeployment "1" ..> "1" Secret

Cluster "1" ..> "1" StaticControlPlane
Cluster "1" ..> "1" StaticCluster

MachineSet "1..*" ..> "1" Cluster
MachineSet "1" ..> "1" StaticMachineTemplate
MachineSet "1" ..> "1" Secret
MachineSet "1" --> "1..*" Machine
MachineSet "1" --> "1..*" StaticMachine

Machine "1..*" ..> "1" Cluster
Machine "1" ..> "1" StaticMachine
Machine "1..*" ..> "1" Secret
Machine "1" --> "1" Instance

StaticInstance "1..*" ..> "1" SSHCredentials
StaticInstance "0..1" ..> "1" StaticMachine
StaticInstance "0..1" ..> "1" Node

StaticMachine "1" ..> "1" Node

Instance "1" ..> "1" Node
Instance "1" ..> "1" Machine

@endurl
